package game.frame;

import com.javaGame.util.MusicUtil;
import com.lovo.netCRM.component.LovoButton;
import game.utils.FileUtils;

import javax.swing.*;
import java.awt.*;

/**
 * @author liuyulai
 * Created with IntelliJ IDEA.
 * Date: 21.5.11
 * Time: 11:27
 * Description: 启动界面
 */
public class StartFrame extends JFrame {
    public static Boolean isTwoPlayerOrNot = false;

    private LovoButton lb = new LovoButton("新游戏", 140, 200, this);
    private LovoButton lb2 = new LovoButton("双人游戏", 140, 230, this);
    private LovoButton lb3 = new LovoButton("查看排行榜", 140, 260, this);
    private LovoButton lb4 = new LovoButton("退出游戏", 140, 290, this);

    public StartFrame() {
        JLabel jlImg = new JLabel();
        Image img = new ImageIcon("img/startFrame.jpg").getImage();
        img = img.getScaledInstance(400, 400, 1);
        jlImg.setIcon(new ImageIcon(img));
        this.add(jlImg);
        this.setSize(400, 400);
        this.setVisible(true);
        this.setLayout(null);
        init();
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
    }

    private void init() {
        lb.addActionListener(e -> {
            new MusicUtil("music/click.mp3", false);
            this.dispose();
            new MainFrame();
        });

        lb2.addActionListener(e -> {
            new MusicUtil("music/click.mp3", false);
            isTwoPlayerOrNot = true;
            this.dispose();
            new MainFrame();
        });

        lb3.addActionListener(e -> {
            new MusicUtil("music/click.mp3", false);
            FileUtils.readPlayerList();
            this.dispose();
            new Leaderboard();
        });
        lb4.addActionListener(e -> {
            new MusicUtil("music/click.mp3", false);
            this.dispose();
        });
    }
}
